package com.tanhua.manage.controller;

import com.tanhua.manage.service.UnfreezeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/manage/users")
public class StateController {
    @Autowired
    UnfreezeService unfreezeService;
    /***
     * 接口名称：用户解冻操作
     * 接口路径：POST/manage/users/unfreeze
     */
    @PostMapping("unfreeze")
    public ResponseEntity<Object> unfreeze(@RequestBody Map<String, Object> map){
        Integer userId = (Integer) map.get("userId");
        String reasonsForThawing = (String) map.get("reasonsForThawing");
        return unfreezeService.Thaw(userId,reasonsForThawing);
    }

    /***
     * 接口名称：用户冻结操作
     * 接口路径：POST/manage/users/freeze
     */
    @PostMapping("freeze")
    public ResponseEntity<Object> freeze(@RequestBody Map<Object, Object> map){
        Integer userId = (Integer) map.get("userId");
        Integer freezingTime = Integer.parseInt(map.get("freezingTime").toString());
        Integer freezingRange = Integer.parseInt(map.get("freezingRange").toString());
        String reasonsForFreezing = (String) map.get("reasonsForFreezing");
        String frozenRemarks = (String) map.get("frozenRemarks");
        return unfreezeService.freeze(userId,freezingTime,freezingRange,reasonsForFreezing,frozenRemarks);
    }
}
